package com.ba360.struts.form;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

public class LoginForm extends ActionForm
{
  private String password;
  private String userName;

  public void reset(ActionMapping mapping, HttpServletRequest request)
  {
    this.userName = null;
    this.password = null;
  }

  public ActionErrors validate(ActionMapping mapping, HttpServletRequest request)
  {
    ActionErrors ae = new ActionErrors();

    String action = request.getParameter("action");
    if (action == null) {
      return ae;
    }

    if (action.equals("Login"))
    {
      if ((this.userName == null) || (this.userName.trim().length() == 0)) {
        ae.add("UserName", new ActionError("error.username.notvalid"));
        return ae;
      }

      if ((this.password == null) || (this.password.trim().length() == 0)) {
        ae.add("Password", new ActionError("error.password.notvalid"));
        return ae;
      }
    }
    return ae;
  }

  public String getPassword()
  {
    return this.password;
  }

  public void setPassword(String password)
  {
    this.password = password;
  }

  public String getUserName()
  {
    return this.userName;
  }

  public void setUserName(String userName)
  {
    this.userName = userName;
  }
}